﻿using System.Collections.Generic;
using System.ServiceModel;
using Metro.Kashikoi.Common.Entity;
using Metro.Kashikoi.Common.ExceptionHandling;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF;
using Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;

namespace Metro.Kashikoi.ServiceContract.Item
{
    /// <summary>
    /// This interface provides methods to manage the item.
    /// </summary>
    [ServiceContractAttribute]
    [ExceptionShielding]
    public interface IItemService
    {
        /// <summary>
        /// Creates a new item.
        /// </summary>
        /// <param name="item">The item to be created.</param>
        /// <returns>The newly created item.</returns>
        [OperationContract]
        [ApplyDataContractResolver]
        [FaultContract(typeof(ServiceFault))]
        [FaultContract(typeof(ValidationFault))]
        StockItem CreateItem(StockItem item);

        /// <summary>
        /// Updates the item.
        /// </summary>
        /// <param name="item">The item to be updated.</param>
        [OperationContract]
        [ApplyDataContractResolver]
        [FaultContract(typeof(ServiceFault))]
        [FaultContract(typeof(ValidationFault))]
        void UpdateItem(StockItem item);

        /// <summary>
        /// Deletes the item.
        /// </summary>
        /// <param name="itemId">The item id.</param>
        [OperationContract]
        [ApplyDataContractResolver]
        [FaultContract(typeof(ServiceFault))]
        [FaultContract(typeof(ValidationFault))]
        void DeleteItem(
            [RangeValidator(0, RangeBoundaryType.Exclusive, int.MaxValue, RangeBoundaryType.Exclusive)]
            int itemId);

        /// <summary>
        /// Gets all items.
        /// </summary>
        /// <returns>A list of item.</returns>
        [OperationContract]
        [ApplyDataContractResolver]
        [FaultContract(typeof(ServiceFault))]
        [FaultContract(typeof(ValidationFault))]
        IList<StockItem> GetAllItems();

        /// <summary>
        /// Imports the items.
        /// </summary>
        /// <param name="path">The file path.</param>
        [OperationContract]
        [ApplyDataContractResolver]
        [FaultContract(typeof(ServiceFault))]
        [FaultContract(typeof(ValidationFault))]
        void ImportItems(
            [NotNullValidator]
            [StringLengthValidator(1, 1024)]
            string path);

        /// <summary>
        /// Creates the charge department.
        /// </summary>
        /// <param name="chargeDepartment">The charge department.</param>
        /// <returns>The newly created charge department.</returns>
        [OperationContract]
        [ApplyDataContractResolver]
        [FaultContract(typeof(ServiceFault))]
        [FaultContract(typeof(ValidationFault))]
        ChargeDepartment CreateChargeDepartment(ChargeDepartment chargeDepartment);

        /// <summary>
        /// Updates the charge department.
        /// </summary>
        /// <param name="chargeDepartment">The charge department.</param>
        [OperationContract]
        [ApplyDataContractResolver]
        [FaultContract(typeof(ServiceFault))]
        [FaultContract(typeof(ValidationFault))]
        void UpdateChargeDepartment(ChargeDepartment chargeDepartment);

        /// <summary>
        /// Deletes the charge department.
        /// </summary>
        /// <param name="chargeDepartmentId">The charge department id.</param>
        [OperationContract]
        [ApplyDataContractResolver]
        [FaultContract(typeof(ServiceFault))]
        [FaultContract(typeof(ValidationFault))]
        void DeleteChargeDepartment(int chargeDepartmentId);

        /// <summary>
        /// Gets all charge departments.
        /// </summary>
        /// <returns>A list of charge department.</returns>
        [OperationContract]
        [ApplyDataContractResolver]
        [FaultContract(typeof(ServiceFault))]
        [FaultContract(typeof(ValidationFault))]
        IList<ChargeDepartment> GetAllChargeDepartments();

        /// <summary>
        /// Gets the item.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="includeCategory">if set to <c>true</c>
        /// the category will be fetched.</param>
        /// <param name="includeVendor">if set to <c>true</c>
        /// the vendor will be fetched.</param>
        /// <param name="includeChargeDepartment">if set to <c>true</c> 
        /// the charge department will be fetched..</param>
        /// <returns>
        /// The stock item.
        /// </returns>
        [OperationContract]
        [ApplyDataContractResolver]
        [FaultContract(typeof(ServiceFault))]
        [FaultContract(typeof(ValidationFault))]
        StockItem GetItem(
            [RangeValidator(0, RangeBoundaryType.Exclusive, int.MaxValue, RangeBoundaryType.Exclusive)]
            int id,
            bool includeCategory = true, bool includeVendor = true,
            bool includeChargeDepartment = true);
    }
}
